package com.jfinal.club._admin.same;
import java.util.HashMap;

import org.json.JSONObject;

import com.baidu.aip.nlp.AipNlp;
import com.jfinal.club._admin.dajuan.DajuanAdminService;

public class Same {
	
	static DajuanAdminService srv;
    public static final String APP_ID = "20185655";
    public static final String API_KEY = "BSPr6viZMXdh7ZCQreQ7EEgD";
    public static final String SECRET_KEY = "xf7t4flXnIHR31routUeqrBKCCvuBAna";

    public int compare(String text1, String text2, String type) {
    	try {
			
        AipNlp client = new AipNlp(APP_ID, API_KEY, SECRET_KEY);
        System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
	    HashMap<String, Object> options = new HashMap<String, Object>();
		options.put("model", type);
		// 短文本相似度
		JSONObject res = client.simnet(text1, text2, options);
		System.out.println(res.toString());
		Thread.sleep(1000);
		int result = (int) Math.ceil(res.getDouble("score") * 10);
	    return result;
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			return 0;
		}
			}
}
